using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class AmmoMalfunction {
	[RuntimeInitializeOnLoadMethod]
	static void SubscribeEvents() {
		Projectile.ProjectileFiring+=ProjectileFiringEventHandler;
	}
	const int id = 2;

	static void ProjectileFiringEventHandler(object _sender,ProjectileEventArgs e) {
		Projectile sender = _sender as Projectile;
		if(sender.stat.consumedAmmo==null) return;
		if(!sender.stat.consumedAmmo.ContainsKey(id)) return;
		if(sender.stat.consumedAmmo[id]<=0) return;
		int roundConsumed = sender.stat.consumedAmmo[id];

		Projectile.Create(
			ProjectileData.nameToData["Explosion"],
			sender.shooterWeapon.muzzleWorldPosition,
			Angle.right,
			sender.shooterMob,
			sender.shooterWeapon,
			sender,
			new Dictionary<int,int>(),
			(Projectile x) => {
				x.stat.damage.baseValue=e.stat.damage;
				x.stat.damageSelf++;
				x.stat.damageFriendly++;
				x.stat.damage.AddMultiply(roundConsumed,0);
			}
		);

		e.stat.damage.AddMultiply(0.3f,1);
		e.stat.speed.AddMultiply(0.3f,0);

	}
}
